package com.apes.fn.scm.retailOrder.service.orderFix;

import com.apes.fn.fico.settleExpense.SettleExpense;
import com.apes.fn.fico.settleExpense.SettleExpenseRepository;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.framework.util.ReflectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 调整赋能定损费用单数据
 *
 * @author wuq
 * @Time 2022-6-23 10:49
 * @Description
 */
@Service
public class RetailFnSettleExpenseDataFix {

    @Autowired
    private SettleExpenseRepository settleExpenseRepository;

    public void fix(SimpleRequest simpleRequest) {
        String id = simpleRequest.get("id");
        SettleExpense settleExpense = settleExpenseRepository.findOne(id);
        negativeAmountSave(settleExpense);
    }


    /**
     * 用于将数据查询到之后，修改金额为负数之后保存
     * @param oldSettleExpense SettleExpense
     */
    private void negativeAmountSave(SettleExpense oldSettleExpense){
        SettleExpense settleExpense = new SettleExpense();

        ReflectUtil.copy(oldSettleExpense, settleExpense,
                "tenant", "payment", "type", "expenseType", "dept", "remark", "lossQuotationAmt", "carLicense", "caseType",
                "origin", "originBusinessType", "source", "sourceBusinessType");

        settleExpense.setAmount(-1 * oldSettleExpense.getAmount());        // 费用金额
        settleExpenseRepository.saveAndFlush(settleExpense);
    }
}
